/**
  * Author: Mei
  * Date: 2020-12-30 19:13
  * Description: 可变参数模板用于函数
  *
  *
  */
#include "../head.h"

template<typename T>
void print(T t) {
    cout << t;
}

template<typename T, typename ...Args>
void print(T t, Args ...args) {
    cout << t << " ";
    print(args...);
}

//第一种获取索引  通过递归+模板特化
template<int ...>
struct TupleIndex {

};
template<int N, int ...indexes> //indexes必须声明为int
struct MakeIndex : MakeIndex<N - 1, N - 1, indexes...> {

};
template<int ...Indexes>
struct MakeIndex<0, Indexes...> {
    typedef TupleIndex<Indexes...> type;
};
//第二种方式获取索引  通过递归+参数拆分  但需要类型Types的个数才能跳出递归
//template<int I, int...Indexes, typename T, typename ...Types>
//struct make_indexes<I, TupleIndex<Indexes...>, T, Types...> {
//    using type = typename make_indexes<I - 1, TupleIndex<Indexes..., I - 1>, Types...>::type;
//};
//template<int I, int...Indexes>
//struct make_indexes<I, TupleIndex<Indexes...>> {
//    using type = TupleIndex<Indexes...>;
//};

void TestF(int a, double b, int c) {
    cout << a + b + c << endl;
}

//template<int ...Args>
//void Test(TupleIndex<Args...> &tp) {
//    print(Args...);
//}

template<typename F, int ...Indexes, typename Tuple>
auto
apply(F &&f, TupleIndex<Indexes...> &&in, Tuple &&tp)
-> decltype(forward<F>(f)(get<Indexes>(tp)...)) {
    return forward<F>(f)(get<Indexes>(tp)...); //没有必要返回函数
}

void Test() {
    apply(TestF, MakeIndex<3>::type(), make_tuple(6, 2, 10));
}

int main() {
    //MakeIndex<7>::type a;
    //make_indexes<7, TupleIndex<>, >::type a;
    //
    Test();


    return 0;
}